package org.fs.dao;

// Generated 2009-02-21 16:41:17 by Hibernate Tools 3.2.4.CR1

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.fs.entities.Airport;
import org.fs.entities.FsConnection;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import static org.hibernate.criterion.Example.create;

/**
 * Home object for domain model class FsConnection.
 * @see org.fs.entities.FsConnection
 * @author Hibernate Tools
 */
public class FsConnectionHome {

	private static final Log log = LogFactory.getLog(FsConnectionHome.class);

	private  SessionFactory sessionFactory;

	public void persist(FsConnection transientInstance) {
		log.debug("persisting FsConnection instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}
	
	public List<FsConnection> getAll(){
		Session s = sessionFactory.getCurrentSession();
		List<FsConnection> a = s.createQuery("from org.fs.entities.FsConnection").list();
		return a;
	}

	public void attachDirty(FsConnection instance) {
		log.debug("attaching dirty FsConnection instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(FsConnection instance) {
		log.debug("attaching clean FsConnection instance");
		try {
			sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(FsConnection persistentInstance) {
		log.debug("deleting FsConnection instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public FsConnection merge(FsConnection detachedInstance) {
		log.debug("merging FsConnection instance");
		try {
			FsConnection result = (FsConnection) sessionFactory
					.getCurrentSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public FsConnection findById(java.math.BigDecimal id) {
		log.debug("getting FsConnection instance with id: " + id);
		try {
			FsConnection instance = (FsConnection) sessionFactory
					.getCurrentSession()
					.get("org.fs.entities.FsConnection", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<FsConnection> findByExample(FsConnection instance) {
		log.debug("finding FsConnection instance by example");
		try {
			List<FsConnection> results = (List<FsConnection>) sessionFactory
					.getCurrentSession().createCriteria(
							"org.fs.entities.FsConnection").add(
							create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
}
